package shortcircuit.basics;

import java.awt.*;
import java.util.ArrayList;

/**
 * This class will control all of the settings related to the walls in the game. <p>
 * This class contains the orientation of the wall, the other walls in the block
 * connected to the wall, and whether the wall is free.
 * @author David Li
 */

public class Wall implements Element
{
	public static final int WEST = 0, NORTH = 1, EAST = 2, SOUTH = 3;
	private ArrayList<Integer> linkedDirections;
	private int _Direction;
	private boolean isFree, isTraversed, isOnFire;
	
	/**
	 * Creates a wall with the specified direction and freedom.
	 * 
	 * @param theDirection The direction that the wall is facing in
	 * @param isFree Whether the wall is free or not
	 * @author David Li
	 */
	Wall(int theDirection, boolean isFree){
		linkedDirections = new ArrayList<Integer>();
		_Direction = theDirection;
		this.isFree = isFree;
	}
	
	
	/**
	 * Returns the wall graphics design.
	 * 
	 * @author David Li
	 */
	public void getGraphics(Graphics g)
	{
		if(isOnFire)
		{
				g.setColor(Color.RED);
			if(_Direction == WEST || _Direction == EAST)
				g.fillRect(0, 0, 3, 40);
			else
				g.fillRect(0, 0, 40, 3);
		}
	}
	
	/**
	 * Sets whether or not the wall is free.
	 * 
	 * @param isFree Whether the current wall is free or not
	 * @author David Li
	 */
	public void setFree(boolean isFree){
		this.isFree = isFree;
	}
	
	/**
	 * Returns whether or not the wall is free. Only used when checking if wall can be traversed.
	 * 
	 * @return Whether the wall is free or not
	 * @author David Li
	 */
	public boolean isFree(){
		return isFree;
	}
	
	/**
	 * Returns whether or not the wall is free.
	 * 
	 * @param inDirection The direction in which the cell is being entered from
	 * @return Whether the wall is free or not
	 * @author David Li
	 */
	public boolean isFree(int inDirection){
		if(!isFree)
			return false;
		for(int index = 0; index < linkedDirections.size(); index++)
			if((int) linkedDirections.get(index) == inDirection)
				return true;
		return false;
	}
	
	/**
	 * Sets the direction the wall is facing in.
	 * 
	 * @param theDirection The direction the current wall should be facing in
	 * @author David Li
	 */
	void setDirection(int theDirection){
		_Direction = theDirection;
	}
	
	/**
	 * Returns the direction the wall is facing in.
	 * 
	 * @return The direction the wall is facing in
	 * @author David Li
	 */
	int getDirection(){
		return _Direction;
	}
	
	/**
	 * Sets the directions that the wall is currently linked to.
	 * 
	 * @param theLinkedDirections The directions the current wall is linked to.
	 * @author David Li
	 */
	public void setLinkedDirection(int theLinkedDirection){
		linkedDirections.add(theLinkedDirection);
	}
	
	/**
	 * Returns the directions that the wall is currently linked to.
	 * 
	 * @return The directions that the current wall is linked to
	 * @author David Li
	 */
	public ArrayList<Integer> getLinkedDirections(){
		return linkedDirections;
	}
	
	/**
	 * Sets whether the wall has been traversed in the detection of complete paths.
	 * 
	 * @param isTraversed Whether the wall has been traversed in the detection of complete paths
	 * @author David Li
	 */
	public void setTraversed(boolean isTraversed){
		this.isTraversed = isTraversed;
	}
	
	/**
	 * Returns whether the wall has been traversed in the detection of complete paths.
	 * 
	 * @return Whether the wall has been traversed in the detection of complete paths
	 * @author David Li
	 */
	public boolean isTraversed(){
		return isTraversed;
	}
	
	public void setOnFire(boolean b)
	{
		isOnFire = b;
	}
	
	public boolean getOnFire()
	{
		return isOnFire;
	}
}
